package com.example.auth.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

@Configuration
public class TokenConfig {
    // 生成JWT令牌
    // 定义解析jwt的口令
    private final String SIGNING_KEY = "lilanyu_jwt";


    // 向Spring容器中保存一个令牌的生成策略
    // 策略: 1.保存在服务器内存中 InMemoryTokenStore
    //      2.保存在客户端
    @Bean
    public TokenStore tokenStore(){
        return new JwtTokenStore(accessTokenConverter());
    }

    // JWT转换器(将json格式信息转换为JWT的对象)
    @Bean
    public JwtAccessTokenConverter accessTokenConverter(){
        JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
        converter.setSigningKey(SIGNING_KEY);
        return converter;
    }
}
